7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 if( defined( 'MEDIAWIKI' ) ) {
13 if($wgUseTeX) require_once( 'Math.php' );
20 var $mHeaders, $mMetatags, $mKeywords;
21 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
22 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
23 var $mSubtitle, $mRedirect, $mStatusCode;
24 var $mLastModified, $mETag, $mCategoryLinks;
25 var $mScripts, $mLinkColours;
27 var $mSuppressQuickbar;
30 var $mContainsOldMagic, $mContainsNewMagic;
31 var $mIsArticleRelated;
33 var $mShowFeedLinks = false;
34 var $mEnableClientCache = true;
35 var $mArticleBodyOnly = false;
39 * Initialise private variables
41 function OutputPage() {
42 $this->mHeaders
= $this->mMetatags
=
43 $this->mKeywords
= $this->mLinktags
= array();
44 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
45 $this->mRedirect
= $this->mLastModified
=
46 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
47 $this->mOnloadHandler
= '';
48 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
49 $this->mSuppressQuickbar
= $this->mPrintable
= false;
50 $this->mLanguageLinks
= array();
51 $this->mCategoryLinks
= array() ;
52 $this->mDoNothing
= false;
53 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
54 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
55 $this->mSquidMaxage
= 0;
58 $this->mRevisionId
= null;
61 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ) ; }
62 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
63 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
65 # To add an http-equiv meta tag, precede the name with "http:"
66 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
67 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
68 function addScript( $script ) { $this->mScripts
.= $script; }
69 function getScript() { return $this->mScripts
; }
71 function setETag($tag) { $this->mETag
= $tag; }
72 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
73 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
75 function addLink( $linkarr ) {
76 # $linkarr should be an associative array of attributes. We'll escape on output.
77 array_push( $this->mLinktags
, $linkarr );
80 function addMetadataLink( $linkarr ) {
81 # note: buggy CC software only reads first "meta" link
82 static $haveMeta = false;
83 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
84 $this->addLink( $linkarr );
89 * checkLastModified tells the client to use the client-cached page if
90 * possible. If sucessful, the OutputPage is disabled so that
91 * any future call to OutputPage->output() have no effect. The method
92 * returns true iff cache-ok headers was sent.
94 function checkLastModified ( $timestamp ) {
95 global $wgCachePages, $wgUser;
96 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
97 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
100 if( !$wgCachePages ) {
101 wfDebug( "CACHE DISABLED\n", false );
104 if( $wgUser->getOption( 'nocache' ) ) {
105 wfDebug( "USER DISABLED CACHE\n", false );
109 $timestamp=wfTimestamp(TS_MW
,$timestamp);
110 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
) );
112 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
113 # IE sends sizes after the date like this:
114 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
115 # this breaks strtotime().
116 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
117 $modsinceTime = strtotime( $modsince );
118 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
119 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
120 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
121 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
122 # Make sure you're in a place you can leave when you call us!
123 header( "HTTP/1.0 304 Not Modified" );
124 $this->mLastModified
= $lastmod;
125 $this->sendCacheControl();
126 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
128 @ob_end_clean
(); // Don't output compressed blob
131 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
132 $this->mLastModified
= $lastmod;
135 wfDebug( "client did not send If-Modified-Since header\n", false );
136 $this->mLastModified
= $lastmod;
140 function getPageTitleActionText () {
149 // Display title is already customized
152 return wfMsg('history_short');
154 // FIXME: bug 2735; not correct for special pages etc
155 return wfMsg('preview');
157 return wfMsg('info_short');
163 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
164 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
165 function setPageTitle( $name ) {
166 global $action, $wgContLang;
167 $name = $wgContLang->convert($name, true);
168 $this->mPagetitle
= $name;
169 if(!empty($action)) {
170 $taction = $this->getPageTitleActionText();
171 if( !empty( $taction ) ) {
172 $name .= ' - '.$taction;
176 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
178 function getHTMLTitle() { return $this->mHTMLtitle
; }
179 function getPageTitle() { return $this->mPagetitle
; }
180 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
181 function getSubtitle() { return $this->mSubtitle
; }
182 function isArticle() { return $this->mIsarticle
; }
183 function setPrintable() { $this->mPrintable
= true; }
184 function isPrintable() { return $this->mPrintable
; }
185 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
186 function isSyndicated() { return $this->mShowFeedLinks
; }
187 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
188 function getOnloadHandler() { return $this->mOnloadHandler
; }
189 function disable() { $this->mDoNothing
= true; }
191 function setArticleRelated( $v ) {
192 $this->mIsArticleRelated
= $v;
194 $this->mIsarticle
= false;
197 function setArticleFlag( $v ) {
198 $this->mIsarticle
= $v;
200 $this->mIsArticleRelated
= $v;
204 function isArticleRelated() { return $this->mIsArticleRelated
; }
206 function getLanguageLinks() { return $this->mLanguageLinks
; }
207 function addLanguageLinks($newLinkArray) {
208 $this->mLanguageLinks +
= $newLinkArray;
210 function setLanguageLinks($newLinkArray) {
211 $this->mLanguageLinks
= $newLinkArray;
214 function getCategoryLinks() {
215 return $this->mCategoryLinks
;
219 * Add an array of categories, with names in the keys
221 function addCategoryLinks($categories) {
222 global $wgUser, $wgContLang;
224 # Add the links to the link cache in a batch
225 $arr = array( NS_CATEGORY
=> $categories );
227 $lb->setArray( $arr );
230 $sk =& $wgUser->getSkin();
231 foreach ( $categories as $category => $arbitrary ) {
232 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
233 $text = $wgContLang->convertHtml( $title->getText() );
234 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
238 function setCategoryLinks($categories) {
239 $this->mCategoryLinks
= array();
240 $this->addCategoryLinks($categories);
243 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
244 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
246 function addHTML( $text ) { $this->mBodytext
.= $text; }
247 function clearHTML() { $this->mBodytext
= ''; }
248 function getHTML() { return $this->mBodytext
; }
249 function debug( $text ) { $this->mDebugtext
.= $text; }
252 function setParserOptions( $options ) {
253 return $this->ParserOptions( $options );
256 function ParserOptions( $options = null ) {
257 return wfSetVar( $this->mParserOptions
, $options );
261 * Set the revision ID which will be seen by the wiki text parser
262 * for things such as embedded {{REVISIONID}} variable use.
263 * @param mixed $revid an integer, or NULL
264 * @return mixed previous value
266 function setRevisionId( $revid ) {
267 $val = is_null( $revid ) ?
null : intval( $revid );
268 return wfSetVar( $this->mRevisionId
, $val );
272 * Convert wikitext to HTML and add it to the buffer
273 * Default assumes that the current page title will
276 function addWikiText( $text, $linestart = true ) {
278 $this->addWikiTextTitle($text, $wgTitle, $linestart);
281 function addWikiTextWithTitle($text, &$title, $linestart = true) {
282 $this->addWikiTextTitle($text, $title, $linestart);
285 function addWikiTextTitle($text, &$title, $linestart) {
287 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
288 $linestart, true, $this->mRevisionId
);
289 $this->addParserOutput( $parserOutput );
292 function addParserOutputNoText( &$parserOutput ) {
293 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
294 $this->addCategoryLinks( $parserOutput->getCategories() );
295 $this->addKeywords( $parserOutput );
296 if ( $parserOutput->getCacheTime() == -1 ) {
297 $this->enableClientCache( false );
301 function addParserOutput( &$parserOutput ) {
302 $this->addParserOutputNoText( $parserOutput );
303 $this->addHTML( $parserOutput->getText() );
307 * Add wikitext to the buffer, assuming that this is the primary text for a page view
308 * Saves the text into the parser cache if possible
310 function addPrimaryWikiText( $text, $article, $cache = true ) {
311 global $wgParser, $wgUser;
313 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
314 $this->mParserOptions
, true, true, $this->mRevisionId
);
316 if ( $article && $parserOutput->getCacheTime() != -1 ) {
317 $parserCache =& ParserCache
::singleton();
318 $parserCache->save( $parserOutput, $article, $wgUser );
321 $this->addParserOutput( $parserOutput );
325 * Add the output of a QuickTemplate to the output buffer
326 * @param QuickTemplate $template
328 function addTemplate( &$template ) {
330 $template->execute();
331 $this->addHTML( ob_get_contents() );
336 * Parse wikitext and return the HTML. This is for special pages that add the text later
338 function parse( $text, $linestart = true ) {
339 global $wgParser, $wgTitle;
340 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
341 $linestart, true, $this->mRevisionId
);
342 return $parserOutput->getText();
351 function tryParserCache( $article, $user ) {
352 $parserCache =& ParserCache
::singleton();
353 $parserOutput = $parserCache->get( $article, $user );
354 if ( $parserOutput !== false ) {
355 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
356 $this->addCategoryLinks( $parserOutput->getCategories() );
357 $this->addKeywords( $parserOutput );
358 $this->addHTML( $parserOutput->getText() );
359 $t = $parserOutput->getTitleText();
361 $this->setPageTitle( $t );
370 * Set the maximum cache time on the Squid in seconds
373 function setSquidMaxage( $maxage ) {
374 $this->mSquidMaxage
= $maxage;
378 * Use enableClientCache(false) to force it to send nocache headers
381 function enableClientCache( $state ) {
382 return wfSetVar( $this->mEnableClientCache
, $state );
385 function uncacheableBecauseRequestvars() {
387 return $wgRequest->getText('useskin', false) === false
388 && $wgRequest->getText('uselang', false) === false;
391 function sendCacheControl() {
392 global $wgUseSquid, $wgUseESI;
395 header("ETag: $this->mETag");
397 # don't serve compressed data to clients who can't handle it
398 # maintain different caches for logged-in users and non-logged in ones
399 header( 'Vary: Accept-Encoding, Cookie' );
400 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
401 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
402 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
405 # We'll purge the proxy cache explicitly, but require end user agents
406 # to revalidate against the proxy on each visit.
407 # Surrogate-Control controls our Squid, Cache-Control downstream caches
408 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
409 # start with a shorter timeout for initial testing
410 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
411 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
412 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
414 # We'll purge the proxy cache for anons explicitly, but require end user agents
415 # to revalidate against the proxy on each visit.
416 # IMPORTANT! The Squid needs to replace the Cache-Control header with
417 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
418 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
419 # start with a shorter timeout for initial testing
420 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
421 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
424 # We do want clients to cache if they can, but they *must* check for updates
425 # on revisiting the page.
426 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
427 header( "Expires: -1" );
428 header( "Cache-Control: private, must-revalidate, max-age=0" );
430 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
432 wfDebug( "** no caching **\n", false );
434 # In general, the absence of a last modified header should be enough to prevent
435 # the client from using its cache. We send a few other things just to make sure.
436 header( 'Expires: -1' );
437 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
438 header( 'Pragma: no-cache' );
443 * Finally, all the text has been munged and accumulated into
444 * the object, let's actually output it:
447 global $wgUser, $wgOutputEncoding;
448 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType, $wgProfiler;
450 if( $this->mDoNothing
){
453 $fname = 'OutputPage::output';
454 wfProfileIn( $fname );
455 $sk = $wgUser->getSkin();
457 if ( '' != $this->mRedirect
) {
458 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
459 # Standards require redirect URLs to be absolute
461 $this->mRedirect
= $wgServer . $this->mRedirect
;
463 if( $this->mRedirectCode
== '301') {
464 if( !$wgDebugRedirects ) {
465 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
467 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
470 $this->sendCacheControl();
472 if( $wgDebugRedirects ) {
473 $url = htmlspecialchars( $this->mRedirect
);
474 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
475 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
476 print "</body>\n</html>\n";
478 header( 'Location: '.$this->mRedirect
);
480 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
481 wfProfileOut( $fname );
484 elseif ( $this->mStatusCode
)
486 $statusMessage = array(
488 101 => 'Switching Protocols',
493 203 => 'Non-Authoritative Information',
495 205 => 'Reset Content',
496 206 => 'Partial Content',
497 207 => 'Multi-Status',
498 300 => 'Multiple Choices',
499 301 => 'Moved Permanently',
502 304 => 'Not Modified',
504 307 => 'Temporary Redirect',
505 400 => 'Bad Request',
506 401 => 'Unauthorized',
507 402 => 'Payment Required',
510 405 => 'Method Not Allowed',
511 406 => 'Not Acceptable',
512 407 => 'Proxy Authentication Required',
513 408 => 'Request Timeout',
516 411 => 'Length Required',
517 412 => 'Precondition Failed',
518 413 => 'Request Entity Too Large',
519 414 => 'Request-URI Too Large',
520 415 => 'Unsupported Media Type',
521 416 => 'Request Range Not Satisfiable',
522 417 => 'Expectation Failed',
523 422 => 'Unprocessable Entity',
525 424 => 'Failed Dependency',
526 500 => 'Internal Server Error',
527 501 => 'Not Implemented',
528 502 => 'Bad Gateway',
529 503 => 'Service Unavailable',
530 504 => 'Gateway Timeout',
531 505 => 'HTTP Version Not Supported',
532 507 => 'Insufficient Storage'
535 if ( $statusMessage[$this->mStatusCode
] )
536 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
539 # Buffer output; final headers may depend on later processing
542 # Disable temporary placeholders, so that the skin produces HTML
543 $sk->postParseLinkColour( false );
545 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
546 header( 'Content-language: '.$wgContLanguageCode );
548 if ($this->mArticleBodyOnly
) {
549 $this->out($this->mBodytext
);
551 wfProfileIn( 'Output-skin' );
552 $sk->outputPage( $this );
553 wfProfileOut( 'Output-skin' );
556 $this->sendCacheControl();
558 wfProfileOut( $fname );
561 function out( $ins ) {
562 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
563 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
566 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
567 if ( false === $outs ) { $outs = $ins; }
572 function setEncodings() {
573 global $wgInputEncoding, $wgOutputEncoding;
574 global $wgUser, $wgContLang;
576 $wgInputEncoding = strtolower( $wgInputEncoding );
578 if( $wgUser->getOption( 'altencoding' ) ) {
579 $wgContLang->setAltEncoding();
583 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
584 $wgOutputEncoding = strtolower( $wgOutputEncoding );
587 $wgOutputEncoding = $wgInputEncoding;
591 * Returns a HTML comment with the elapsed time since request.
592 * This method has no side effects.
593 * Use wfReportTime() instead.
597 function reportTime() {
598 $time = wfReportTime();
603 * Note: these arguments are keys into wfMsg(), not text!
605 function errorpage( $title, $msg ) {
608 $this->mDebugtext
.= 'Original title: ' .
609 $wgTitle->getPrefixedText() . "\n";
610 $this->setPageTitle( wfMsg( $title ) );
611 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
612 $this->setRobotpolicy( 'noindex,nofollow' );
613 $this->setArticleRelated( false );
614 $this->enableClientCache( false );
615 $this->mRedirect
= '';
617 $this->mBodytext
= '';
618 $this->addWikiText( wfMsg( $msg ) );
619 $this->returnToMain( false );
626 * Display an error page indicating that a given version of MediaWiki is
629 * @param mixed $version The version of MediaWiki needed to use the page
631 function versionRequired( $version ) {
634 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
635 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
636 $this->setRobotpolicy( 'noindex,nofollow' );
637 $this->setArticleRelated( false );
638 $this->mBodytext
= '';
640 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
641 $this->returnToMain();
645 * Display an error page noting that a given permission bit is required.
646 * This should generally replace the sysopRequired, developerRequired etc.
647 * @param string $permission key required
649 function permissionRequired( $permission ) {
652 $this->setPageTitle( wfMsg( 'badaccess' ) );
653 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
654 $this->setRobotpolicy( 'noindex,nofollow' );
655 $this->setArticleRelated( false );
656 $this->mBodytext
= '';
658 $sk = $wgUser->getSkin();
659 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
660 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
661 $this->returnToMain();
667 function sysopRequired() {
670 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
671 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
672 $this->setRobotpolicy( 'noindex,nofollow' );
673 $this->setArticleRelated( false );
674 $this->mBodytext
= '';
676 $sk = $wgUser->getSkin();
677 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
678 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
679 $this->returnToMain();
685 function developerRequired() {
688 $this->setPageTitle( wfMsg( 'developertitle' ) );
689 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
690 $this->setRobotpolicy( 'noindex,nofollow' );
691 $this->setArticleRelated( false );
692 $this->mBodytext
= '';
694 $sk = $wgUser->getSkin();
695 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
696 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
697 $this->returnToMain();
700 function loginToUse() {
701 global $wgUser, $wgTitle, $wgContLang;
703 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
704 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
705 $this->setRobotpolicy( 'noindex,nofollow' );
706 $this->setArticleFlag( false );
707 $this->mBodytext
= '';
708 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
709 $sk = $wgUser->getSkin();
710 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
711 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
712 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
714 # We put a comment in the .html file so a Sysop can diagnose the page the
716 $this->addHTML( "\n<!--" .
717 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
719 $wgTitle->getDBkey() . '-->' );
720 $this->returnToMain(); # Flip back to the main page after 10 seconds.
723 function databaseError( $fname, $sql, $error, $errno ) {
724 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
726 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
727 $this->setRobotpolicy( 'noindex,nofollow' );
728 $this->setArticleRelated( false );
729 $this->enableClientCache( false );
730 $this->mRedirect
= '';
732 if( !$wgShowSQLErrors ) {
733 $sql = wfMsg( 'sqlhidden' );
736 if ( $wgCommandLineMode ) {
737 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
738 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
740 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
741 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
744 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
748 $this->mBodytext
= $msg;
753 function readOnlyPage( $source = null, $protected = false ) {
754 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
756 $this->setRobotpolicy( 'noindex,nofollow' );
757 $this->setArticleRelated( false );
760 $this->setPageTitle( wfMsg( 'viewsource' ) );
761 $this->addWikiText( wfMsg( 'protectedtext' ) );
763 $this->setPageTitle( wfMsg( 'readonly' ) );
765 $reason = $wgReadOnly;
767 $reason = file_get_contents( $wgReadOnlyFile );
769 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
772 if( is_string( $source ) ) {
773 if( strcmp( $source, '' ) == 0 ) {
775 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
776 $source = wfMsgWeirdKey ( $wgTitle->getText() ) ;
778 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
781 $rows = $wgUser->getOption( 'rows' );
782 $cols = $wgUser->getOption( 'cols' );
783 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
784 htmlspecialchars( $source ) . "\n</textarea>";
785 $this->addHTML( $text );
788 $this->returnToMain( false );
791 function fatalError( $message ) {
792 $this->setPageTitle( wfMsg( "internalerror" ) );
793 $this->setRobotpolicy( "noindex,nofollow" );
794 $this->setArticleRelated( false );
795 $this->enableClientCache( false );
796 $this->mRedirect
= '';
798 $this->mBodytext
= $message;
803 function unexpectedValueError( $name, $val ) {
804 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
807 function fileCopyError( $old, $new ) {
808 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
811 function fileRenameError( $old, $new ) {
812 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
815 function fileDeleteError( $name ) {
816 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
819 function fileNotFoundError( $name ) {
820 $this->fatalError( wfMsg( 'filenotfound', $name ) );
824 * return from error messages or notes
825 * @param $auto automatically redirect the user after 10 seconds
826 * @param $returnto page title to return to. Default is Main Page.
828 function returnToMain( $auto = true, $returnto = NULL ) {
829 global $wgUser, $wgOut, $wgRequest;
831 if ( $returnto == NULL ) {
832 $returnto = $wgRequest->getText( 'returnto' );
834 $returnto = htmlspecialchars( $returnto );
836 $sk = $wgUser->getSkin();
837 if ( '' == $returnto ) {
838 $returnto = wfMsgForContent( 'mainpage' );
840 $link = $sk->makeKnownLink( $returnto, '' );
842 $r = wfMsg( 'returnto', $link );
844 $titleObj = Title
::newFromText( $returnto );
845 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
847 $wgOut->addHTML( "\n<p>$r</p>\n" );
851 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
852 * and uses the first 10 of them for META keywords
854 function addKeywords( &$parserOutput ) {
856 $this->addKeyword( $wgTitle->getPrefixedText() );
858 $links2d =& $parserOutput->getLinks();
859 foreach ( $links2d as $ns => $dbkeys ) {
860 foreach( $dbkeys as $dbkey => $id ) {
861 $this->addKeyword( $dbkey );
862 if ( ++
$count > 10 ) {
873 function headElement() {
874 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
875 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
877 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
878 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
883 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
885 if ( '' == $this->getHTMLTitle() ) {
886 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
889 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
890 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
891 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
892 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
894 $ret .= $this->getHeadLinks();
896 if( $this->isPrintable() ) {
899 $media = "media='print'";
901 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
902 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
904 $sk = $wgUser->getSkin();
905 $ret .= $sk->getHeadScripts();
906 $ret .= $this->mScripts
;
907 $ret .= $sk->getUserStyles();
909 if ($wgUseTrackbacks && $this->isArticleRelated())
910 $ret .= $wgTitle->trackbackRDF();
916 function getHeadLinks() {
917 global $wgRequest, $wgStylePath;
919 foreach ( $this->mMetatags
as $tag ) {
920 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
922 $tag[0] = substr( $tag[0], 5 );
926 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
929 $p = $this->mRobotpolicy
;
930 if( $p !== '' && $p != 'index,follow' ) {
931 // http://www.robotstxt.org/wc/meta-user.html
932 // Only show if it's different from the default robots policy
933 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
936 if ( count( $this->mKeywords
) > 0 ) {
941 $ret .= "<meta name=\"keywords\" content=\"" .
942 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
944 foreach ( $this->mLinktags
as $tag ) {
946 foreach( $tag as $attr => $val ) {
947 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
951 if( $this->isSyndicated() ) {
952 # FIXME: centralize the mime-type and name information in Feed.php
953 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
954 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
955 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
956 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
963 * Turn off regular page output and return an error reponse
964 * for when rate limiting has triggered.
968 function rateLimited() {
971 wfHttpError( 500, 'Internal Server Error',
972 'Sorry, the server has encountered an internal error. ' .
973 'Please wait a moment and hit "refresh" to submit the request again.' );